package com.jfy.cmai.robot.base;

import android.content.Context;
import android.content.IntentFilter;
import android.content.pm.ActivityInfo;
import android.net.ConnectivityManager;
import android.os.Bundle;
import android.view.Window;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import com.gyf.immersionbar.ImmersionBar;
import com.jfy.cmai.robot.R;


public abstract class BaseActivity extends AppCompatActivity {

    public Context mContext;
    //private NetworkChangeReceiver receiver;

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //EventBus.getDefault().register(this);
        //PushAgent.getInstance(this).onAppStart();
        doBeforeSetcontentView();
        setContentView(getLayoutId());
        mContext = this;
        registerNetworkChangeReceiver();
        initView();
        initData();
    }

    //获取布局文件
    public abstract int getLayoutId();

    //初始化view
    public abstract void initView();

    protected abstract void initData();

    private void doBeforeSetcontentView() {
        // 把actvity放到application栈中管理
        // AppManager.getAppManager().addActivity(this);
        //AppActivityManagerUtils.getAppManager().addActivity(this);
        // 无标题
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        // 设置竖屏
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
        //初始化沉浸式
        initImmersionBar();
    }

    /**
     * 初始化沉浸式
     */
    protected void initImmersionBar() {

        //设置共同沉浸式样式
        ImmersionBar.with(this)
               // .statusBarColor(R.color.white)
                .statusBarDarkFont(true)
                .fitsSystemWindows(true)
                .navigationBarDarkIcon(true)
                .fullScreen(false)
                .init();

    }

    /**
     * 注册网络监听广播
     */
    private void registerNetworkChangeReceiver() {
//        receiver = new NetworkChangeReceiver(this);
//        IntentFilter filter = new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION);
//        registerReceiver(receiver, filter);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
//        if (receiver != null) {
//            unregisterReceiver(receiver);
//            receiver.onDestroy();
//            receiver = null;
//        }
//        // 取消注册
//        if (this.getClass().isAnnotationPresent(BindEventBus.class)) {
//            //EventBusHelper.unregister(this);
//        }

    }

    @Override
    protected void onResume() {
        super.onResume();
        //MobclickAgent.onResume(this);
    }

    @Override
    protected void onPause() {
        super.onPause();
        //MobclickAgent.onPause(this);
    }
}